﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EVEPreChargeDataMonitor
{
    using System;
    using System.Collections.Generic;
    using System.IO;

    public class Tray
    {
        public string TrayName { get; set; }
        public string TypeId { get; set; }
        public string LotId { get; set; }
        public Dictionary<int, int> Cells { get; set; }

        public Tray(string trayName)
        {
            TrayName = trayName;
            Cells = new Dictionary<int, int>();
        }

        public void AddCell(int cellId, int cellValue)
        {
            Cells[cellId] = cellValue;
        }

        public override string ToString()
        {
            return $"Tray({TrayName}, Type ID: {TypeId}, Lot ID: {LotId}, Cells Count: {Cells.Count})";
        }
    }

    class Program
    {
        static void Main()
        {
            string filePath = "你的文件路径.txt"; // 替换为实际文件路径
            Tray tray = null;

            try
            {
                // 读取文件内容
                var lines = File.ReadAllLines(filePath);

                foreach (var line in lines)
                {
                    if (line.StartsWith("托盘名"))
                    {
                        // 创建托盘实例
                        tray = new Tray("托盘名");
                    }
                    else if (line.StartsWith("[TYPE]"))
                    {
                        tray.TypeId = GetValue(lines, ref line);
                    }
                    else if (line.StartsWith("[LOT]"))
                    {
                        tray.LotId = GetValue(lines, ref line);
                    }
                    else if (line.StartsWith("[CELL]"))
                    {
                        // 解析CELL数据
                        for (int i = 1; i <= 256; i++)
                        {
                            int cellValue = 69078 + i; // 69079到69334
                            tray.AddCell(i, cellValue);
                        }
                    }
                }

                // 输出托盘信息
                Console.WriteLine(tray);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"读取文件时出错: {ex.Message}");
            }
        }

        static string GetValue(string[] lines, ref string line)
        {
            // 获取当前行的下一个值
            line = lines[++Array.IndexOf(lines, line)];
            return line.Split('=')[1].Trim(); // 返回等号后的值
        }
    }
